#include "widget.h"
#include "ui_widget.h"

#include<thread>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //获取当前的值
//    int val = ui->lcdNumber->intValue();

//    while (true) {
//        //先休眠  1s
//        std::this_thread::sleep_for(std::chrono::seconds(1));
//        if(val<=0)
//        {
//            break;
//        }
//        ui->lcdNumber->display(--val);
//    }


    //创建线程
    std::thread  t([this]() {
        int val = ui->lcdNumber->intValue();
        this->ui->lcdNumber->intValue();
        while(true)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
            if(val <= 0)
            {
                break;
            }

            val -= 1;
            ui->lcdNumber->display(val);
        }
    });
}

Widget::~Widget()
{
    delete ui;
}

